home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / dial / d_rcvdata.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  1.6 KB  |  67 lines

  1. # include  "d_returns.h"
  2.  
  3. /*
  4.  *     D_RCVDATA
  5.  *
  6.  *     this routine is called to read data bytes from the other side.
  7.  *     if there are currently any unread characters in the internal
  8.  *     read queue, they are returned before another packet is read.
  9.  *
  10.  *     buffer -- place to load the data
  11.  *
  12.  *     nbytes -- the maximum number of bytes that should be returned
  13.  *               if an oet is found, then not all that the caller
  14.  *               requests may be returned.
  15.  *
  16.  *     eot -- pointer to a variable that is set if the packet, or the
  17.  *            one queued, contained an EOT
  18.  */
  19.  
  20. d_rcvdata(buffer, nbytes, eot)
  21.   register char  *buffer;
  22.   register int  nbytes;
  23.   int  *eot;
  24.     {
  25.     extern char  *d_rdqpt;
  26.     extern int  d_rdqcnt, d_rdeot;
  27.     register int  count;
  28.     int  result;
  29.  
  30.     count = 0;
  31.  
  32.     while (1)
  33.       {
  34.       /*  transfer data until the max is reached or this packet
  35.        *  is emptied.
  36.        */
  37.       while (nbytes && d_rdqcnt)
  38.         {
  39.         *buffer++ = *d_rdqpt++;
  40.         count++;
  41.         nbytes--;
  42.         d_rdqcnt--;
  43.         }
  44.  
  45.       /*  If there are no more packets available, return EOT  */
  46.       if ((d_rdqcnt == 0) && d_rdeot)
  47.         {
  48.         *eot = 1;
  49.         d_rdeot = 0;
  50.         return(count);
  51.         }
  52.  
  53.       /*  If there is no more room to transfer to, just return  */
  54.       if (nbytes == 0)
  55.         {
  56.         *eot = 0;
  57.         return(count);
  58.         }
  59.  
  60.       /*  Else we come here.  No more data in this packet, but there
  61.        *  are more packets to read.  Do it.
  62.        */
  63.       if ((result = d_getdata()) < 0)
  64.         return(result);
  65.       }
  66.     }
  67.